#include "dominion.c"
#include "assert.h"
#include "stdio.h"
#include "rngs.c"

void checkBuyCard(struct gameState* state, int* cards);

int main(){
	int *cards = kingdomCards(7,8,9,10,11,12,13,14,15,16);
	struct gameState *state = newGame();
	
	initializeGame(4, cards, -1, state);
	
	for(int i = 0; i < 4; i++){
		checkBuyCard(state, cards);
	}
	return 0;
}

void checkBuyCard(struct gameState* state, int* cards){
	int card;
	int supply;
	int coins;
	int buys;
	
	state->coins = (int)(Random() * 15) + 5; // Anywhere from 5 to 20 coins
	state->numBuys = (int)(Random() * 4 + 1); // And from 1 to 5 buys
	
	for (int i = 0; i < 3; i++){
		card = cards[(int)(Random()*9.99)]; // Selects any of the possible cards; use 9.99 because if it ended up being 10, would cause a segfault
		supply = supplyCount(card, state);
		coins = state->coins;
		buys = state->numBuys;
		
		if (!buyCard(card, state)){
			// All of these should have changed if the buy went through
			if( supply != supplyCount(card, state) + 1){
				printf("Buy happened, supply count mismatch! Previous supply: %d. Current supply: %d\n", supply, supplyCount(card, state));
				assert(0);
			}
			if( buys != state->numBuys + 1){
				printf("Buy happened, buy count mismatch! Previous buys: %d. Current buys: %d\n", buys, state->numBuys);
				assert(0);
			}
			if( coins != state->coins + getCost(card)){
				printf("Buy happened, coin count mismatch! Previous coins: %d. Current coins: %d\n", coins, state->coins);
				assert(0);
			}
		} else {
			// If the buy failed, none of these should have changed
			if( buys != state->numBuys){
				printf("Buy failed, buy count mismatch! Previous buys: %d. Current buys: %d\n", buys, state->numBuys);
				assert(0);
			}
			if( coins != state->coins){
				printf("Buy failed, coin count mismatch! Previous coins: %d. Current coins: %d\n", coins, state->coins);
				assert(0);
			}
			if( supply != supplyCount(card, state)){
				printf("Buy failed, supply count mismatch! Previous supply: %d. Current supply: %d\n", supply, supplyCount(card, state));
				assert(0);
			}
		}
	}
}

























